<?php
namespace Common\Model;
use MongoDB\Driver\Query;
use Think\Model;
class LiveCameraAngleModel extends VRLiveModel
{
	protected $autoCheckFields = false;
	
	protected $_validate = array(
	);
	
	protected $_auto = array(
			
	);
	
	public function get_camera_angle_list($live_id){
		$list = $this->query("select a.*,b.real_name,c.channel_name as source_name,txy_channel_id from vrlive.live_camera_angle a left join vradmin1.admin_user b on (a.operator_id=b.admin_id ) left join vrlive.live_channel c on (a.source_id=c.channel_id ) where a.live_id=".$live_id);
		return$list;
//		return $this->where(array('live_id'=> $live_id))->select();
	}
	//推流业务员
	public function getLiveOperatorList(){
		//查看 除admin 外全部管理员
//		$admin_user = new AdminUserModel();
//		$manager_all = $admin_user->where("status=1 and admin_id != 1")->field("admin_id,real_name")->select();

//根据 权限返回 推流人员列表
		$where     = "快直播-直播推流-访问指派给自己的直播列表";
		$and_where = "快直播-高级管理-直播推流";

		//查看 对应的权限
		$power_action = M("vradmin1.power_action", null);
		$powers = $power_action->field("action_id")->where("action_name = '".$where."' or action_name = '".$and_where."'")->select();
		$powers = i_array_column($powers, "action_id");

		$res_role = '';
		//查看 所有角色和权限 关联信息
		$role_power_relation = M("vradmin1.role_power_relation", null);
		$role_powers = $role_power_relation->select();

		//匹配 对应的角色id
		foreach ($role_powers as $key=>$val) {
			$action_arr = explode(',', $val['action_ids']);
			foreach ($powers as $k => $power_id) {
				if (in_array($power_id, $action_arr)) {
					$res_role .= $val['role_id'] . ',';
				}
			}
		}
		if(strlen($res_role) > 2) {
			$res_role = substr($res_role, 0,-1);
		}else{
			return false;
		}

		//查看对应的用户信息
		$list = $this->query("select distinct b.admin_id,b.real_name from vradmin1.admin_role as a left join vradmin1.admin_user as b on (b.admin_id = a.admin_id)  where a.role_id in (".$res_role.") and b.admin_id != '' order by b.admin_id asc");

		return $list;
		

//		//一维
//		$manager_all_one = i_array_column($manager_all, 'admin_id');
//
//		//查看 正在执行推流人员
//		$now_list = $this->where("status=1 and signal_source = 1 and operator_id != ''")->field('distinct operator_id as admin_id')->select();
//		//一维
//		$now_lists = i_array_column($now_list,'admin_id');
//
//		//如果 推流人员 不属于 现有管理员，删除（数据问题）
//		foreach ($now_list as $key=>$val) {
//			if(!in_array($val['admin_id'],$manager_all_one)){
//				unset($now_lists[$key]);
//			}
//		}
//
//		//排除 正在执行推流人员
//		foreach ($manager_all as $key=>$val){
//			if(in_array($val['admin_id'], $now_lists)){
//				unset($manager_all[$key]);
//			}
//		}
//		//重新排序
//		sort($manager_all);

//		return $manager_all;
	}
	
}

